package agile.hustler.activities;

import java.util.Scanner;

import agile.hustler.activities.R;
import agile.hustler.activities.R.drawable;
import agile.hustler.activities.R.id;
import agile.hustler.activities.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class CharacterScreen extends Activity {
	/** Called when the activity is first created. */
	Drawable charIcon;
	TextView txtName, txtClass, txtLvl;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.characterscreen);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

		Bundle b = getIntent().getExtras();
		final String data = b.getString("key");

		Typeface face = Typeface.createFromAsset(getAssets(),
				"fonts/SEVERINA.ttf");

		txtName = (TextView) findViewById(R.id.TextName);
		txtClass = (TextView) findViewById(R.id.TextClass);
		txtLvl = (TextView) findViewById(R.id.TextLevel);

		txtName.setTypeface(face);
		txtClass.setTypeface(face);
		txtLvl.setTypeface(face);

		Scanner scanner = new Scanner(data);
		scanner.useDelimiter(" ");
		String type = scanner.next();
		String name = scanner.next();
		String charLvl = scanner.next();

		txtName.setText(name);
		txtLvl.setText("Level: " + charLvl);

		if (type.equalsIgnoreCase("tank")) {
			charIcon = getResources().getDrawable(R.drawable.chartank);
			txtClass.setText("TANK");
		}

		else if (type.equalsIgnoreCase("caster")) {
			charIcon = getResources().getDrawable(R.drawable.charcaster);
			txtClass.setText("CASTER");
		}

		else {
			charIcon = getResources().getDrawable(R.drawable.chardps);
			txtClass.setText("DPS");
		}
		LinearLayout imView = (LinearLayout) findViewById(R.id.CharBg);
		imView.setBackgroundDrawable(charIcon);

		findViewById(R.id.ButtonStats).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {

						Bundle B = new Bundle();

						B.putString("key", data);

						Intent intent = new Intent(CharacterScreen.this,
								StatsPopup.class);

						intent.putExtras(B);

						startActivity(intent);
						finish();
						System.gc();

					}
				});

		findViewById(R.id.ButtonStore).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {

						Bundle B = new Bundle();

						B.putString("key", data);
						Intent intent = new Intent(CharacterScreen.this,
								store.class);
						intent.putExtras(B);
						startActivity(intent);
						finish();
						System.gc();
					}
				});

		findViewById(R.id.ButtonFight).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {

						Bundle B = new Bundle();

						B.putString("key", data);

						Intent intent = new Intent(CharacterScreen.this,
								ComSetup.class);

						intent.putExtras(B);

						startActivity(intent);
						finish();
						System.gc();
					}
				});

		findViewById(R.id.ButtonBack).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {
						startActivity(new Intent(CharacterScreen.this,
								StartScreen.class));
						finish();
						System.gc();
					}
				});
	}
}